package com.abe.bathsystem.contract.presenter;

import com.abe.bathsystem.contract.CommonContract;
import com.abe.bathsystem.contract.CommonModel;
import com.abe.bathsystem.entity.ReqBaseEntity;
import com.abe.bathsystem.entity.ReqConstant;
import com.abe.bathsystem.entity.http.HttpUserEntity;
import com.abe.libcore.utils.normal.ToastUtils;
import com.abe.mvpcore.BasePresenter;
import com.abe.mvpcore.OnResultListener;

public class LoginPresenter extends BasePresenter<CommonContract.LoginView, CommonModel> implements CommonContract.LoginPresenter {

    @Override
    public void login(String phone, String password) {
        getModel().login(phone, password, new OnResultListener<ReqBaseEntity<HttpUserEntity>>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onEnd() {
                LoginPresenter.this.onEnd(LoginPresenter.class.getSimpleName() + "-login");
            }

            @Override
            public void onSuccess(ReqBaseEntity<HttpUserEntity> data) {
                if (LoginPresenter.this.onSuccess(data)) {
                    if (data.getCode() == ReqConstant.NET_RESULT_OK) {
                        getView().onLogin(data.getCode() == ReqConstant.NET_RESULT_OK, data.getData());
                    } else {
                        ToastUtils.show(data.getMsg());
                    }
                }
            }

            @Override
            public void onFailure(String message) {
                LoginPresenter.this.onFailure(LoginPresenter.class.getSimpleName() + "-login");
            }
        });
    }
}